package com.iwhalecloud.bss.kite.cucc.spec.impl.query;

import com.google.common.collect.Lists;
import com.iwhalecloud.bss.kite.client.dto.spec.ObjAttrRstrRulDTO;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.goods.IGoodsService;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.CuccOfferOriginalInfoCache;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.ProdRelOfferCache;
import com.iwhalecloud.bss.kite.cucc.spec.impl.transfer.ProductsInfoTransfer;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryProductService;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProdAttrRstrRulCache;
import com.iwhalecloud.bss.kite.dataservice.cache.ProductCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.dataservice.entity.ObjectLabelRel;
import com.iwhalecloud.bss.kite.dataservice.entity.ProductCat;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdAttr;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdAttrScope;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.ProdCatalog;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Product;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProdAttrMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProdAttrScopeMapper;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.ProductMapper;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ProductQueryService implements IQueryProductService {

    private static final String PRODUCT_TYPE_PAY = "pay";

    @Resource
    private ProdAttrMapper prodAttrMapper;

    @Resource
    private ProductMapper productMapper;

    @Autowired
    private IGoodsService goodsService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Product getProduct(String prodId) {
        //没提供产品信息查询接口的产品信息获取方式
        Product product = productMapper.selectinfoByProdId(prodId);
        if (KiteObjectUtils.isEmpty(product)) {
            product = getProductFromInf(prodId);
        }
        return product;
    }

    @Override
    public Product getProdByBaseOfferIdAndProdNbr(String baseOfferId, String prodNbr) {
        if (KiteStringUtils.isAnyEmpty(baseOfferId, prodNbr)) {
            return null;
        }
        Example example = new Example(Product.class);
        example.createCriteria().andEqualTo("baseOfferId", baseOfferId).andEqualTo("prodNbr", prodNbr)
            .andEqualTo("prodFuncType", "102").andEqualTo("statusCd", "1000");
        return productMapper.selectOneByExample(example);
    }

    @Override
    public List<ProdAttr> listProdAttrsByAccessProdId(String prodId) {
        List<ProdAttr> prodAttrList = getProdAttrFromInf(prodId);
        if (KiteListUtils.isEmpty(prodAttrList)) {
            Product product = ProductCache.get(prodId);
            prodAttrList = prodAttrMapper.listProdAttrByAccessProdId(prodId, product.getCateId());
        }
        return prodAttrList;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public List<ProdAttr> listProdAttrByProdId(String prodId) {
        List<ProdAttr> prodAttrList = getProdAttrFromInf(prodId);
        if (KiteListUtils.isEmpty(prodAttrList)) {
            prodAttrList = prodAttrMapper.listProdAttrByProdId(prodId);
        }
        return prodAttrList;
    }

    @Override
    public List<ProdAttr> listProdAttrsByAccessProdIdNew(String offerId, String prodId, String cateId, String provinceId) {
        List<ProdAttr> prodAttrs = prodAttrMapper.listProdAttrByAccessProdId(prodId, cateId);
        this.filterByProvinceNbr(prodAttrs, provinceId, offerId);
        // 设置是否联动标识
        this.setIsLinkage(prodAttrs, prodId);
        return prodAttrs;
    }

    @Override
    public List<ProdAttr> listProdAttrsByAccessProdIdNew(String offerId, String prodId, String cateId) {
        return this.listProdAttrsByAccessProdIdNew(offerId, prodId, cateId, ContextUtil.getLoginInfo().getUserInfo().getPostProvinceNbr());
    }

    /**
     * 设置属性是否联动标识
     * 如果prod_ext_attr.handler_class有配置，则认为是联动属性
     * 如果属性在属性规则联动表（obj_attr_rstr_rul等相关表）中，作为A端，则认为是联动属性
     * @param prodAttrs
     * @param prodId
     */
    private void setIsLinkage(List<ProdAttr> prodAttrs, String prodId) {
        if (KiteListUtils.isEmpty(prodAttrs)) {
            return;
        }
        for (ProdAttr prodAttr : prodAttrs) {
            if (KiteStringUtils.isNotBlank(prodAttr.getHandlerClass())) {
                prodAttr.setLinkageFlag(true);
            }
            // forward为true是A端
            List<ObjAttrRstrRulDTO> ruleDtos = ProdAttrRstrRulCache.get(prodId, prodAttr.getFieldName(), true);
            if (KiteListUtils.isNotEmpty(ruleDtos)) {
                prodAttr.setLinkageFlag(true);
            }
        }
    }

    /**
     * 增加prod_attr_scope表，同一属性可以根据不同区域进行定制化配置
     */
    private void filterByProvinceNbr(List<ProdAttr> prodAttrs, String provinceNbr, String offerId) {
        if (KiteListUtils.isEmpty(prodAttrs) || KiteStringUtils.isEmpty(provinceNbr)) {
            return;
        }
        List<String> prodAttrIdList = prodAttrs.stream().map(ProdAttr::getProdAttrId).collect(Collectors.toList());
        ProdAttrScopeMapper prodAttrScopeMapper = SpringUtil.getBean(ProdAttrScopeMapper.class);
        Example example = new Example(ProdAttrScope.class);
        example.createCriteria().andIn("prodAttrId", prodAttrIdList)
            .andEqualTo("statusCd", KeyConsts.COMMON_STATUS_VALIDATE);
        List<ProdAttrScope> prodAttrScopeList = prodAttrScopeMapper.selectByExample(example);
        if (KiteListUtils.isEmpty(prodAttrScopeList)) {
            return;
        }
        // 找出配置了当前区域的prodAttrId
        List<String> currentScopeIdList = Lists.newArrayList();
        // 属性在其他区域的配置
        List<String> otherScopeIdList = Lists.newArrayList();
        // scope表对应默认值
        Map<String,String> scopeMap = new HashMap<>();
        // 是否五大双线代收费或落地管理产品，因落地产品productId与正常产品相同，此处只取prodAttrScope配置了的属性
        List<DcPublic> list = DcPublicCache.get("20210719001");
        List<DcPublic> scopelist = DcPublicCache.get("20220412001");
        boolean flag = (list != null) && list.stream().anyMatch(dcPublic -> KiteStringUtils.isEqual(offerId, dcPublic.getCodeb()));
        boolean  scopeflag = (scopelist != null) && scopelist.stream().anyMatch(dcPublic -> KiteStringUtils.isEqual(offerId, dcPublic.getCodeb()));

        prodAttrScopeList.forEach(prodAttrScope -> {
            if ((((KiteStringUtils.isEmpty(prodAttrScope.getOfferId()) || KiteStringUtils.equals(prodAttrScope.getOfferId(),"0")) && !flag && !scopeflag)
                || KiteStringUtils.equals(prodAttrScope.getOfferId(), offerId))
                && KiteStringUtils.equalsAny(prodAttrScope.getApplyRegionCode(), provinceNbr, "09")) {
                currentScopeIdList.add(prodAttrScope.getProdAttrId().toString());
                // scope表属性默认值
                if(KiteStringUtils.isNotEmpty(prodAttrScope.getDefaultValue())){
                    scopeMap.put(Long.toString(prodAttrScope.getProdAttrId()),prodAttrScope.getDefaultValue());
                }
            }
            else {
                otherScopeIdList.add(prodAttrScope.getProdAttrId().toString());
            }
        });

        if(flag||scopeflag) {
            // 五大双线代收费或落地管理产品，排除prodAttrScope未配置的属性
            prodAttrs.removeIf(prodAttr -> !currentScopeIdList.contains(prodAttr.getProdAttrId()));
        } else {
            otherScopeIdList.removeIf(os->currentScopeIdList.contains(os));
            // 找出配置了区域的属性的fieldName
            List<String> scopeFieldNameList = prodAttrs.stream().filter(prodAttr -> currentScopeIdList.contains(prodAttr.getProdAttrId()))
                .map(ProdAttr::getFieldName).collect(Collectors.toList());

            // 排除同属性其他区域的配置（fieldName相同则认为是同一个属性）
            prodAttrs.removeIf(prodAttr -> !currentScopeIdList.contains(prodAttr.getProdAttrId()) && scopeFieldNameList
                .contains(prodAttr.getFieldName()) || otherScopeIdList.contains(prodAttr.getProdAttrId()));
        }
        //scope表有配置默认值时取scope配置
        if(KiteMapUtils.isNotEmpty(scopeMap)&&KiteListUtils.isNotEmpty(prodAttrs)){
            prodAttrs.forEach(pdAttr->{
                String defaultValue = scopeMap.get(pdAttr.getProdAttrId());//默认值
                if(KiteStringUtils.isNotEmpty(defaultValue)){
                    pdAttr.setDefaultValue(defaultValue);
                    //pdAttr.setAttrValue(defaultValue);
                }
            });
        }
        // 同款产品不同省份，装机地址PAGE_URL不一致情况
        dealAttrPageUrl(prodAttrs, provinceNbr, offerId);
    }

    /**
     * 同款产品不同省份，装机地址PAGE_URL不一致处理
     * @param prodAttrs
     * @param provinceNbr
     * @param offerId
     */
    private void dealAttrPageUrl(List<ProdAttr> prodAttrs, String provinceNbr, String offerId) {
        List<DcPublic> dcPublics = DcPublicCache.getByPcode("2202281001", "ATTR_PAGE_URL", offerId);
        if (KiteListUtils.isNotEmpty(dcPublics)) {
            dcPublics.forEach(dcPublic -> {
                String provinceCode = dcPublic.getCodea();
                if (provinceCode.contains(provinceNbr)) {
                    prodAttrs.stream().filter(prodAttr -> KiteStringUtils.equals(prodAttr.getFieldName(), dcPublic.getCodeb()))
                        .forEach(attr -> {
                            attr.setPageUrl(dcPublic.getCodec());
                        });
                }
            });
        }
    }

    @Override
    public ProductCat getProductCat(String prodCatType) {
        return null;
    }

    @Override
    public List<ProdCatalog> listProdCatalogsByProdId(String prodId) {
        return Collections.emptyList();
    }

    @Override
    public List<ObjectLabelRel> listProductLabels(String prodId) {
        return Collections.emptyList();
    }

    @SuppressWarnings("unchecked")
    private Product getProductFromInf(String prodId) {
        //没提供产品信息查询接口的产品信息获取方式
        String offerId = ProdRelOfferCache.get(prodId);
        if (KiteStringUtils.isEmpty(offerId)) {
            return null;
        }
        Map<String, Object> goodsInfo = CuccOfferOriginalInfoCache.get(offerId);
        if (KiteMapUtils.isEmpty(goodsInfo)) {
            goodsInfo = goodsService.queryGoodsByOfferId(offerId);
        }
        if (goodsInfo == null || !goodsInfo.containsKey("productCategroy")) {
            return null;
        }
        List<Map> productCategroys = (List<Map>) goodsInfo.get("productCategroy");
        if (KiteListUtils.isNotEmpty(productCategroys)) {
            for (Map productCategroy : productCategroys) {
                String productType = KiteMapUtils.getString(productCategroy, "productType");

                //如果是资费产品，不加载，用可选包去处理
                if (PRODUCT_TYPE_PAY.equals(productType)) {
                    continue;
                }
                List<Map> products = (List<Map>) productCategroy.get("products");
                if (KiteListUtils.isEmpty(products)) {
                    continue;
                }
                Map product = products.stream().filter(prod -> prodId.equals(prod.get("productCode"))).findAny().get();
                if (product != null) {
                    Map<String, Object> category = (Map<String, Object>) product.get("category");
                    String cateId = (String) category.get("categoryId");
                    product.put("productType", productType);
                    product.put("baseOfferId", offerId);

                    //产品缓存
                    return ProductsInfoTransfer.convertProduct(product, cateId, offerId);
                }
            }
        }
        return null;
    }

    @SuppressWarnings("unchecked")
    private List<ProdAttr> getProdAttrFromInf(String prodId) {
        //没提供产品信息查询接口的产品信息获取方式
        String offerId = ProdRelOfferCache.get(prodId);
        if (KiteStringUtils.isEmpty(offerId)) {
            return null;
        }
        Map<String, Object> goodsInfo = CuccOfferOriginalInfoCache.get(offerId);
        if (KiteMapUtils.isEmpty(goodsInfo)) {
            goodsInfo = goodsService.queryGoodsByOfferId(offerId);
        }
        if (goodsInfo == null || !goodsInfo.containsKey("productCategroy")) {
            return null;
        }
        List<Map> productCategroys = (List<Map>) goodsInfo.get("productCategroy");
        if (KiteListUtils.isNotEmpty(productCategroys)) {
            for (Map productCategroy : productCategroys) {
                String productType = KiteMapUtils.getString(productCategroy, "productType");

                //如果是资费产品，不加载，用可选包去处理
                if (PRODUCT_TYPE_PAY.equals(productType)) {
                    continue;
                }
                List<Map> products = (List<Map>) productCategroy.get("products");
                if (KiteListUtils.isEmpty(products)) {
                    continue;
                }
                Map product = products.stream().filter(prod -> prodId.equals(prod.get("productCode"))).findAny().get();
                if (product != null) {
                    Map<String, Object> category = (Map<String, Object>) product.get("category");
                    String cateId = (String) category.get("categoryId");
                    product.put("productType", productType);
                    product.put("baseOfferId", offerId);

                    List<Map<String, Object>> prodAttrs = (List<Map<String, Object>>) product.get("productAttrs");
                    return ProductsInfoTransfer.convertProdAttr(prodAttrs, prodId, cateId);
                }
            }
        }
        return null;

    }
    @Override
    public List<KiteAttr> getProductHisAttrs(String prodId,String offerId) {
        List<KiteAttr> kiteAttrs = new ArrayList<>();
        if(KiteStringUtils.isAnyEmpty(prodId,offerId)){
            ErrorConsts.BUSI_COMMON_ERROR.throwOut("获取历史节点缺少参数！");
        }
        //String offerId = ProdRelOfferCache.get(prodId);
        Map<String, Object> goodsInfo = goodsService.queryGoodsByOfferId(offerId);
        //StringBuffer s = new StringBuffer();
        //s.append("{\"goodsSku\":\"10002958\",\"cateName\":\"安全产品类（全国）\",\"jkProductId\":\"10002958\",\"goodsSource\":\"ZQ\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\",\"productCategroy\":[{\"province\":\"09\",\"jkServiceId\":\"80000434\",\"cateName\":\"安全产品基础产品（全国）\",\"categoryId\":\"80000434\",\"productType\":\"base\",\"products\":[{\"productAttrs\":[{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000106\",\"attrValCodes\":\"10002958\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"产品编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000175\",\"attrValCodes\":\"80000434\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"服务编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000185\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"包编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200004488\",\"attrValCodes\":\"110007294,110007295,110007296,110007297,110007298,110007299,110007300,110007301,110007302,110007303,1_0000422,1_0000151\",\"edited\":true,\"valueType\":\"OPTIONS\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[{\"valueName\":\"金融行业\",\"valueCode\":\"110007294\"},{\"valueName\":\"传媒和互联网\",\"valueCode\":\"110007295\"},{\"valueName\":\"政府行业\",\"valueCode\":\"110007296\"},{\"valueName\":\"教育行业\",\"valueCode\":\"110007297\"},{\"valueName\":\"医疗行业\",\"valueCode\":\"110007298\"},{\"valueName\":\"交通行业\",\"valueCode\":\"110007299\"},{\"valueName\":\"文化旅游\",\"valueCode\":\"110007300\"},{\"valueName\":\"工业互联网\",\"valueCode\":\"110007301\"},{\"valueName\":\"能源行业\",\"valueCode\":\"110007302\"},{\"valueName\":\"生态环境\",\"valueCode\":\"110007303\"},{\"valueName\":\"企业\",\"valueCode\":\"1_0000422\"},{\"valueName\":\"其他\",\"valueCode\":\"1_0000151\"}],\"required\":true,\"attrName\":\"行业\"}],\"productCode\":\"10002958\",\"categoryCode\":\"80000434\",\"jkServiceId\":\"80000434\",\"category\":{\"province\":\"09\",\"jkServiceId\":\"80000434\",\"cateName\":\"安全产品基础产品（全国）\",\"categoryId\":\"80000434\",\"productType\":\"base\"},\"jkProductId\":\"10002958\",\"productName\":\"安全产品主产品\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"status\":\"VALID\"}]}],\"cateId\":\"2000880\",\"activities\":[],\"members\":[{\"min\":\"0\",\"max\":\"0\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000193\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 15:57:18\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"安全专线\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"安全专线\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"0\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000194\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 17:04:56\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"域名无忧高级套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000195\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 17:06:23\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"域名无忧基础套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"域名无忧\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"99\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50040384\",\"goodsPictrues\":[],\"effectTime\":\"2021-09-01 16:27:02\",\"endTime\":\"2099-12-31 23:59:59\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"联通云盾漏洞扫描\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50040385\",\"goodsPictrues\":[],\"effectTime\":\"2021-09-01 16:34:40\",\"endTime\":\"2099-12-31 23:59:59\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"联通云盾网站安全监测\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"联通云盾\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"99\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000191\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:41:38\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"抗D先锋典型套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000190\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:41:38\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"抗D先锋标准套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"抗D先锋\",\"memberType\":\"additional\"}],\"historyData\":{\"members\":[{\"goodsSku\":\"50041139\",\"goodsName\":\"抗D先锋标准套餐2019版\"},{\"goodsSku\":\"50041137\",\"goodsName\":\"抗D先锋典型套餐2019版\"},{\"goodsSku\":\"50041135\",\"goodsName\":\"安全专线2019版\"}],\"products\":[{\"productAttrs\":[{\"attrCode\":\"200004488\",\"edited\":false,\"showed\":false,\"keyAttr\":false,\"attrValues\":[{\"valueName\":\"测试111\",\"valueCode\":\"121212\"}],\"required\":false,\"attrName\":\"测试111失效\"}],\"productCode\":\"10002958\",\"productName\":\"测试资费修改功能基础业务产品\",\"productType\":\"base\"}]},\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:46:17\",\"endTime\":\"2099-12-31 00:00:00\",\"brand\":\"U\",\"goodsName\":\"安全产品主产品\",\"goodsDescr\":\"\",\"goodsAttrs\":[],\"status\":\"LAUNCHED\"}");
        //s.append("{\"goodsSku\":\"10002958\",\"cateName\":\"安全产品类（全国）\",\"jkProductId\":\"10002958\",\"goodsSource\":\"ZQ\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\",\"productCategroy\":[{\"province\":\"09\",\"jkServiceId\":\"80000434\",\"cateName\":\"安全产品基础产品（全国）\",\"categoryId\":\"80000434\",\"productType\":\"base\",\"products\":[{\"productAttrs\":[{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000106\",\"attrValCodes\":\"10002958\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"产品编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000175\",\"attrValCodes\":\"80000434\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"服务编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200000185\",\"edited\":true,\"valueType\":\"INPUT\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[],\"required\":true,\"attrName\":\"包编码\"},{\"defaultAttrValCodes\":\"\",\"attrCode\":\"200004488\",\"attrValCodes\":\"110007294,110007295,110007296,110007297,110007298,110007299,110007300,110007301,110007302,110007303,1_0000422,1_0000151\",\"edited\":true,\"valueType\":\"OPTIONS\",\"showed\":true,\"keyAttr\":false,\"attrValues\":[{\"valueName\":\"金融行业\",\"valueCode\":\"110007294\"},{\"valueName\":\"传媒和互联网\",\"valueCode\":\"110007295\"},{\"valueName\":\"政府行业\",\"valueCode\":\"110007296\"},{\"valueName\":\"教育行业\",\"valueCode\":\"110007297\"},{\"valueName\":\"医疗行业\",\"valueCode\":\"110007298\"},{\"valueName\":\"交通行业\",\"valueCode\":\"110007299\"},{\"valueName\":\"文化旅游\",\"valueCode\":\"110007300\"},{\"valueName\":\"工业互联网\",\"valueCode\":\"110007301\"},{\"valueName\":\"能源行业\",\"valueCode\":\"110007302\"},{\"valueName\":\"生态环境\",\"valueCode\":\"110007303\"},{\"valueName\":\"企业\",\"valueCode\":\"1_0000422\"},{\"valueName\":\"其他\",\"valueCode\":\"1_0000151\"}],\"required\":true,\"attrName\":\"行业\"}],\"productCode\":\"10002958\",\"categoryCode\":\"80000434\",\"jkServiceId\":\"80000434\",\"category\":{\"province\":\"09\",\"jkServiceId\":\"80000434\",\"cateName\":\"安全产品基础产品（全国）\",\"categoryId\":\"80000434\",\"productType\":\"base\"},\"jkProductId\":\"10002958\",\"productName\":\"安全产品主产品\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"status\":\"VALID\"}]}],\"cateId\":\"2000880\",\"activities\":[],\"members\":[{\"min\":\"0\",\"max\":\"0\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000193\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 15:57:18\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"安全专线\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"安全专线\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"0\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000194\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 17:04:56\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"域名无忧高级套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000195\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 17:06:23\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"域名无忧基础套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"域名无忧\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"99\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50040384\",\"goodsPictrues\":[],\"effectTime\":\"2021-09-01 16:27:02\",\"endTime\":\"2099-12-31 23:59:59\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"联通云盾漏洞扫描\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50040385\",\"goodsPictrues\":[],\"effectTime\":\"2021-09-01 16:34:40\",\"endTime\":\"2099-12-31 23:59:59\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"联通云盾网站安全监测\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"联通云盾\",\"memberType\":\"additional\"},{\"min\":\"0\",\"max\":\"99\",\"memberGoods\":[{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000191\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:41:38\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"抗D先锋典型套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"},{\"keyAttrs\":[],\"cateId\":\"2000881\",\"activities\":[],\"goodsSku\":\"50000190\",\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:41:38\",\"endTime\":\"2099-12-31 00:00:00\",\"cateName\":\"安全附加产品类（全国）\",\"goodsName\":\"抗D先锋标准套餐\",\"saleProvinces\":[{\"provinceCode\":\"09\",\"provinceName\":\"全国\"}],\"goodsType\":\"single\"}],\"memberName\":\"抗D先锋\",\"memberType\":\"additional\"}],\"historyData\":{\"members\":[{\"goodsSku\":\"50041139\",\"goodsName\":\"抗D先锋标准套餐2019版\"},{\"goodsSku\":\"50041137\",\"goodsName\":\"抗D先锋典型套餐2019版\"},{\"goodsSku\":\"50041135\",\"goodsName\":\"安全专线2019版\"}],\"products\":[{\"productAttrs\":[{\"attrCode\":\"200004488\",\"edited\":false,\"showed\":false,\"keyAttr\":false,\"attrValues\":[{\"valueName\":\"测试111\",\"valueCode\":\"121212\"}],\"required\":false,\"attrName\":\"测试111失效\"}],\"productCode\":\"10002958\",\"productName\":\"测试资费修改功能基础业务产品\",\"productType\":\"base\"}]},\"goodsPictrues\":[],\"effectTime\":\"2021-03-23 10:46:17\",\"endTime\":\"2099-12-31 00:00:00\",\"brand\":\"U\",\"goodsName\":\"安全产品主产品\",\"goodsDescr\":\"\",\"goodsAttrs\":[],\"status\":\"LAUNCHED\"}");
        //goodsInfo = JSON.parseObject(s.toString());
        List<Map> historyDataByNode = ProductsInfoTransfer.getHistoryDataByNode(goodsInfo, "products", KiteStringUtils.concatWithSymbol(LocalKeyConsts.PRODUCT_TYPE_BASE,LocalKeyConsts.PRODUCT_TYPE_ADD, SymbolConsts.COMMA));
        if(KiteListUtils.isNotEmpty(historyDataByNode)){
            Map historyData = historyDataByNode.stream().filter(hisNode -> KiteStringUtils.equals(prodId, KiteMapUtils.getString(hisNode, "productCode"))).findFirst().orElse(null);
            if(KiteMapUtils.isNotEmpty(historyData)){
                kiteAttrs = ProductsInfoTransfer.convertHisProdAttr(historyData);
            }
        }
        return kiteAttrs;
    }
}
